//
//  mm_popupEditViewController.m
//  HondaPro_2
//
//  Created by Eric on 13-9-22.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "mm_popupEditViewController.h"
#import "MainMenuDataModel.h"

@interface mm_popupEditViewController ()


@end

@implementation mm_popupEditViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.view.frame = CGRectMake(0, 0, 500, 600);
        
        self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.remarksText.layer.borderColor = [UIColor blackColor].CGColor;
    self.remarksText.layer.borderWidth = 1.0;
    self.numsText.text=@"1";
}


//保存数据
-(BOOL)saveData
{
    BOOL flag = true;
    if (self.numsText.text.length>0) {
        if ([self.numsText.text isEqualToString:@"0"]) {
            UIAlertView *tip = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"数量必须大于0" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [tip show];
            return false;
        }
        int num = [self.numsText.text intValue];
        NSString *remark = self.remarksText.text;
        MainMenuDataModel *mainModel = [MainMenuDataModel sharedMainMenuDataModel];
        if (self.isNewOperation) {//新增
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setObject:@"" forKey:@"ITEM_ID"];
            [dic setObject:self.bianhaoDisLbl.text forKey:MM_OUT_CHECK_OUT_CHECK_NUMBER_KEY_STR_];//编号
            [dic setObject:self.leixingDisLbl.text forKey:MM_OUT_CHECK_CHECK_ITEM_KEY_STR_];//类型
            [dic setObject:@(num) forKey:MM_OUT_CHECK_DEFECT_COUNT_KEY_STR_];//数量
            [dic setObject:remark forKey:MM_OUT_CHECK_DEFECT_DESCRIPTION_KEY_STR_];//备注
            NSString *pointStr = [NSString stringWithFormat:@"%d,%d",(NSInteger)(self.currentPoint.x/2.0),(NSInteger)(self.currentPoint.y/2.0)];//位置
            [dic setObject:pointStr forKey:@"POINT"];
            [dic setObject:@"A" forKey:@"STATUS"];
            [mainModel.arrOutCheck addObject:dic];
        }else{
            
            NSMutableDictionary *dic = mainModel.arrOutCheck[self.selectedRow];
            [dic setObject:@(num) forKey:MM_OUT_CHECK_DEFECT_COUNT_KEY_STR_];//数量
            [dic setObject:remark forKey:MM_OUT_CHECK_DEFECT_DESCRIPTION_KEY_STR_];//备注
            [dic setObject:@"U" forKey:@"STATUS"];
        }
    }else{
        return false;
    }
    return flag;

}

@end
